//
//  GSRegisterView.m
//  GameSky
//
//  Created by lanou on 16/1/19.
//  Copyright © 2016年 NiRongfei. All rights reserved.
//

#import "GSRegisterView.h"
@interface GSRegisterView () <UITextFieldDelegate>
@end
@implementation GSRegisterView
#pragma mark--------------自定义初始化--------------------
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        // 夜间模式
        self.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);
        
        CGFloat height = frame.size.height;
        CGFloat minRow = height / 2 / 12;
        CGFloat minHeight = height / 2 / 6;
// 手机号
        self.phoneNumTextField = [[UITextField alloc] initWithFrame:CGRectMake(minRow, minHeight, kScreenWidth - 2 * minRow, minHeight)];
        // 左视图
        UIImageView *imageVPhone = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, minHeight, minHeight)];
        _phoneNumTextField.leftView = imageVPhone;
        imageVPhone.image = [UIImage imageNamed:@"common_Icon_Phone_13x18_UIMode_Day@2x"];
        imageVPhone.contentMode = UIViewContentModeCenter;
        
        //tag
        _phoneNumTextField.tag = 100;
        _phoneNumTextField.leftViewMode = UITextFieldViewModeAlways;
        _phoneNumTextField.keyboardType = UIKeyboardTypePhonePad;
        //代理
        _phoneNumTextField.delegate = self;
        _phoneNumTextField.borderStyle = UITextBorderStyleRoundedRect;
        _phoneNumTextField.placeholder = @"请输入手机号";
        // clear按钮
        _phoneNumTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
        [self addSubview:_phoneNumTextField];
// 用户名
        self.userNameTextField = [[UITextField alloc] initWithFrame:CGRectMake(_phoneNumTextField.left, _phoneNumTextField.bottom + 14, _phoneNumTextField.width, _phoneNumTextField.height)];
        _userNameTextField.borderStyle = UITextBorderStyleRoundedRect;
        // 左视图
        UIImageView *imageVUserName = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, minHeight, minHeight)];
          imageVUserName.image = [UIImage imageNamed:@"common_Icon_Account_16x16_UIMode_Day@2x"];
        imageVUserName.contentMode = UIViewContentModeCenter;
        // 代理
        _userNameTextField.delegate = self;
        _userNameTextField.tag = 101;
        _userNameTextField.leftViewMode = UITextFieldViewModeAlways;
        _userNameTextField.leftView = imageVUserName;
        _userNameTextField.placeholder = @"请输入用户名";
        _userNameTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
        [self addSubview:_userNameTextField];
// 密码
        self.passwordTextField = [[UITextField alloc] initWithFrame:CGRectMake(_userNameTextField.left, _userNameTextField.bottom + 14, _userNameTextField.width, _userNameTextField.height)];
        _passwordTextField.borderStyle = UITextBorderStyleRoundedRect;
        // 左视图
        UIImageView *imageVPassword = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, minHeight, minHeight)];
        
        imageVPassword.image = [UIImage imageNamed:@"common_Icon_PasswordLock_16x16_UIMode_Day@2x"];
        imageVPassword.contentMode =  UIViewContentModeCenter;
        
        // 代理
        _passwordTextField.delegate = self;
        _passwordTextField.tag = 102;
        _passwordTextField.leftViewMode = UITextFieldViewModeAlways;
        _passwordTextField.leftView = imageVPassword;
        _passwordTextField.placeholder = @"请输入密码";
        _passwordTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
        [self addSubview:_passwordTextField];
// 验证码
        self.securityNumTextField = [[UITextField alloc] initWithFrame:CGRectMake(_passwordTextField.left, _passwordTextField.bottom + 14, _passwordTextField.width * 0.6, _passwordTextField.height)];
        _securityNumTextField.borderStyle = UITextBorderStyleRoundedRect;
        // 左视图
        UIImageView *imageVSecurityNum = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, minHeight, minHeight)];
        imageVSecurityNum.image = [UIImage imageNamed:@"common_Icon_VerificationCode_16x16_UIMode_Day@2x"];
        imageVSecurityNum.contentMode = UIViewContentModeCenter;
        
        //_securityNumTextField.keyboardType = UIKeyboardTypeNumberPad;
        // 代理
        _securityNumTextField.delegate = self;
        _securityNumTextField.tag = 103;
        _securityNumTextField.leftViewMode = UITextFieldViewModeAlways;
        _securityNumTextField.leftView = imageVSecurityNum;
        _securityNumTextField.placeholder = @"请输入验证码";
        _securityNumTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
        [self addSubview:_securityNumTextField];
// 获取验证码button
        self.getSecurityNumButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _getSecurityNumButton.frame = CGRectMake(_securityNumTextField.right + 8, _securityNumTextField.top, _passwordTextField.width - _securityNumTextField.width - 8, _securityNumTextField.height);
        [_getSecurityNumButton setTitle:@"获取验证码" forState:(UIControlStateNormal)];
        [_getSecurityNumButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        _getSecurityNumButton.backgroundColor = [UIColor colorWithRed:155/255.0 green:37/255.0 blue:34/255.0 alpha:1.0];
        _getSecurityNumButton.titleLabel.font = [UIFont boldSystemFontOfSize:18];
        [self addSubview:_getSecurityNumButton];
// 同意声明
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(_securityNumTextField.left, _securityNumTextField.bottom, _passwordTextField.width, _passwordTextField.height)];
        
        [self addSubview:view];
        UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, view.height)];
        imageV.image = [UIImage imageNamed:@"gsUICheckBox_IconChecked@2x"];
        imageV.contentMode = UIViewContentModeCenter;
        [view addSubview:imageV];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(imageV.right, 0, view.width - imageV.right, imageV.height)];
        label.font = [UIFont systemFontOfSize:14];
        label.text = [NSString stringWithFormat:@"我已经同意%c服务条款与声明%c",'"','"'];
        [view addSubview:label];
// 注册按钮
        self.registerButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _registerButton.frame = CGRectMake(_passwordTextField.left, view.bottom, _passwordTextField.width, _passwordTextField.height);
        _registerButton.backgroundColor = [UIColor colorWithRed:155/255.0 green:37/255.0 blue:34/255.0 alpha:1.0];
        [_registerButton setTitle:@"注册" forState:(UIControlStateNormal)];
        [_registerButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        [self addSubview:_registerButton];
        
    }
    return self;
}
#pragma mark---------------回收键盘----------------------
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
#pragma mark------------------------------------------------
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
